package edu.tcc.iot.utils;

import java.sql.ResultSet;
import java.sql.SQLException;

import edu.tcc.iot.domain.Product;
import edu.tcc.iot.domain.ProductInfo;
import edu.tcc.iot.domain.Shelf;

public class DaoUtils {
	
	public static Product productFromResultSet(ResultSet product, ResultSet productInfo) throws SQLException{
		if(product == null || productInfo == null){
			return null;
		}
		ProductInfo info = new ProductInfo(productInfo.getLong("product_id"), productInfo.getString("name"), productInfo.getDouble("quantity"), productInfo.getDouble("price"), productInfo.getDate("validate"));
		return new Product(product.getLong("id"), info);
	}
	
	public static Shelf shelfFromResultSet(ResultSet shelf) throws SQLException{
		if(shelf == null || !shelf.first())
		{
			return null;
		}
		return new Shelf(shelf.getLong("id"));
	}

}
